pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let parse_input = |s: &str| -> (String, u32) {
        let parts: Vec<&str> = s.trim_end_matches(')').split('(').collect();
        (
            parts[0].trim().to_string(),
            parts.get(1).and_then(|b| b.parse().ok()).unwrap_or(10),
        )
    };

    let to_digit_char = |d: u32| -> char {
        match d {
            0..=9 => (b'0' + d as u8) as char,
            10..=35 => ((d - 10) as u8 + b'a') as char,
            _ => unreachable!(),
        }
    };

    let (num, from_base) = parse_input(num_str);
    let decimal = u32::from_str_radix(&num, from_base).unwrap();

    let result: String = std::iter::successors(Some(decimal), |&n| (n > 0).then(|| n / to_base))
        .take_while(|&n| n > 0)
        .map(|n| to_digit_char(n % to_base))
        .collect::<Vec<_>>()
        .into_iter()
        .rev()
        .collect();

    result
}
